function _defineProperty(t, e, a) {
    return e in t ? Object.defineProperty(t, e, {
        value: a,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : t[e] = a, t;
}

var app = getApp();

Page(_defineProperty({
    data: {
        color: "#34aaff",
        status: '',
        order_list: [],
        show_no_data_tip: !1,
        hide: 1,
        qrcode: "",
        pagenum: 1,
        storelist: [],
        mygd: !1,
        jzgd: !0
    },
    // 跳转商家
    tzsjxq: function(t) {
        wx.navigateTo({
            url: "/zh_cjdianc/pages/takeout/takeoutindex?storeid=" + this.data.odinfo.order.store_id
        });
    },
    tzsjxq2: function(t) {
        wx.navigateTo({
            url: "ddxq?oid=" + t.currentTarget.dataset.sid + "&indexs=" + t.currentTarget.dataset.indexs
        });
    },
    tzpjdd: function(t) {
        wx.navigateTo({
            url: "pjdd?oid=" + t.currentTarget.dataset.oid + "&indexs=" + t.currentTarget.dataset.indexs
        });
    },
    hide: function(t) {
        this.setData({
            hide: 1
        });
    },
    hxqh: function(t) {
        var e = this,
            a = t.currentTarget.dataset.id,
            o = t.currentTarget.dataset.sjid;
        wx.showLoading({
            title: "加载中",
            mask: !0
        }), app.util.request({
            url: "entry/wxapp/ZtCode",
            cachetime: "0",
            data: {
                store_id: o,
                order_id: a
            },
            success: function(t) {
                e.setData({
                    hx_code: t.data,
                    hide: 2
                });
            }
        });
    },
    onShow: function() {
        let ths = this,
            idx = wx.getStorageSync("idx");
        if (wx.getStorageSync("order_Refresh") == true) {
            this.setData({
                order_list: [],
                storelist: [],
                pagenum: 1,
            });
            this.reLoad();
        }
        if (idx && ths.data.order_list.length > 0) {
            let olist = ths.data.order_list;
            olist[idx].order.state = 5;
            ths.setData({
                order_list: olist
            })
            wx.setStorageSync("idx", '');
        }
    },
    // 下拉刷新
    onPullDownRefresh: function() {
        this.setData({
            isPull: true,
            pagenum: 1,
        });
        this.reLoad();
    },
    onLoad: function(t) {
        app.setNavigationBarColor(this);
        var a = this;
        getApp().xtxx1 && app.pageOnLoad(a), app.util.request({
            url: "entry/wxapp/System",
            cachetime: "0",
            success: function(t) {
                wx.setStorageSync("order_Refresh", false)
                var e = t.data;
                "2" == e.model && (getApp().sjid = e.default_store), "4" == e.model && (getApp().sjid = e.default_store),
                    null == getApp().xtxx1 && (getApp().xtxx1 = e, app.pageOnLoad(a)), "" == t.data.dc_name && (t.data.dc_name = "店内"),
                    "" == t.data.wm_name && (t.data.wm_name = "外卖"), a.setData({
                        System: t.data
                    });
            }
        });
        this.setData({
            status: t.status,
        }), this.reLoad();
    },
    // 切换状态
    ChageStatus: function(t) {
        let status = t.currentTarget.dataset.status;
        this.setData({
                order_list: [],
                storelist: [],
                pagenum: 1,
                status: status
            }),
            this.reLoad();
    },
    reLoad: function() {
        this.setData({
            mygd: !1
        })
        var t,
            a = this,
            e = this.data.status || "",
            o = wx.getStorageSync("users").id,
            n = this.data.pagenum;
        '' == e && (t = ""),
            2 == e && (t = ""),
            3 == e && (t = ""),
            "4" == e && (e = "4", t = "2"),
            "5" == e && (e = "6,7,8,9,10", t = "3"),
            app.util.request({
                url: "entry/wxapp/MyOrder",
                cachetime: "0",
                data: {
                    dn_state: t,
                    state: e,
                    user_id: o,
                    page: n,
                    pagesize: 10
                },
                success: function(t) {
                    if (a.data.isPull == true) {
                        a.setData({
                            order_list: [],
                            storelist: [],
                            isPull: false
                        })
                    }
                    t.data.length < 10 ?
                        a.setData({
                            mygd: !0,
                            isShow: true,
                            jzgd: !0
                        }) :
                        a.setData({
                            jzgd: !0,
                            isShow: true,
                            pagenum: a.data.pagenum + 1
                        });
                    var e = a.data.storelist;
                    e = function(t) {
                            for (var e = [], a = 0; a < t.length; a++) - 1 == e.indexOf(t[a]) && e.push(t[a]);
                            return e;
                        }(e = e.concat(t.data)),
                        a.setData({
                            order_list: e,
                            storelist: e
                        });
                    wx.stopPullDownRefresh();
                }
            });
    },
    onReachBottom: function() {
        !this.data.mygd && this.data.jzgd && (this.setData({
            jzgd: !1
        }), this.reLoad());
    },
    canceldd: function(t) {
        var ths = this,
            e = t.currentTarget.dataset.id,
            idx = t.currentTarget.dataset.indexs;
        wx.showModal({
            title: "提示",
            content: "是否取消该订单？",
            cancelText: "否",
            confirmText: "是",
            success: function(t) {
                if (t.cancel) return !0;
                t.confirm && (wx.showLoading({
                    title: "操作中"
                }), app.util.request({
                    url: "entry/wxapp/CancelOrder",
                    cachetime: "0",
                    data: {
                        order_id: e
                    },
                    success: function(t) {
                        "1" == t.data ? (wx.showToast({
                            title: "取消成功",
                            icon: "success",
                            duration: 1e3
                        }), setTimeout(function() {
                            let olist = ths.data.order_list;
                            olist[idx].order.state = 5;
                            ths.setData({
                                order_list: olist
                            })
                        }, 1e3)) : wx.showToast({
                            title: "请重试",
                            icon: "loading",
                            duration: 1e3
                        });
                    }
                }));
            }
        });
    },
    orderPay: function(t) {
        var e = getApp().getOpenId,
            a = wx.getStorageSync("users").id,
            o = t.currentTarget.dataset.id,
            n = t.currentTarget.dataset.money,
            s = t.currentTarget.dataset.type,
            ths = this,
            idx = t.currentTarget.dataset.indexs;
        "5" == s ?
            wx.showModal({
                title: "提示",
                content: "您的支付方式为餐后支付，请到收银台付款"
            }) : (wx.showLoading({
                title: "正在提交",
                mask: !0
            }), app.util.request({
                url: "entry/wxapp/pay",
                cachetime: "0",
                data: {
                    openid: e,
                    money: n,
                    order_id: o
                },
                success: function(t) {
                    wx.hideLoading(), wx.requestPayment({
                        timeStamp: t.data.timeStamp,
                        nonceStr: t.data.nonceStr,
                        package: t.data.package,
                        signType: t.data.signType,
                        paySign: t.data.paySign,
                        success: function(t) {

                        },
                        complete: function(t) {
                            "requestPayment:fail cancel" == t.errMsg && wx.showToast({
                                title: "取消支付",
                                icon: "loading",
                                duration: 1e3
                            }), "requestPayment:ok" == t.errMsg && (wx.showToast({
                                    title: "支付成功",
                                    duration: 1e3
                                }), 1 == s &&
                                setTimeout(function() {
                                    let olist = ths.data.order_list;
                                    olist[idx].order.state = 2;
                                    ths.setData({
                                        order_list: olist
                                    })
                                }, 1e3), 2 == s &&
                                setTimeout(function() {
                                    let olist = ths.data.order_list;
                                    olist[idx].order.state = 2;
                                    ths.setData({
                                        order_list: olist
                                    })
                                }, 1e3));
                        }
                    });
                }
            }));
    },
    orderRevoke: function(t) {
        var ths = this,
            e = t.currentTarget.dataset.id,
            idx = t.currentTarget.dataset.indexs;
        wx.showModal({
            title: "提示",
            content: "是否删除该订单？",
            cancelText: "否",
            confirmText: "是",
            success: function(t) {
                if (t.cancel) return !0;
                t.confirm && (wx.showLoading({
                    title: "操作中"
                }), app.util.request({
                    url: "entry/wxapp/DelOrder",
                    cachetime: "0",
                    data: {
                        order_id: e
                    },
                    success: function(t) {
                        "1" == t.data ? (wx.showToast({
                                    title: "删除成功",
                                    icon: "success",
                                    duration: 1e3
                                }),
                                setTimeout(function() {
                                    let olist = ths.data.order_list;
                                    olist[idx].order.state = 404;
                                    ths.setData({
                                        order_list: olist
                                    })
                                }, 1e3)) :
                            wx.showToast({
                                title: "请重试",
                                icon: "loading",
                                duration: 1e3
                            });
                    }
                }));
            }
        });
    },
    txsj: function(t) {
        wx.makePhoneCall({
            phoneNumber: t.currentTarget.dataset.tel
        });
    },
    sqtk: function(e) {
        wx.showModal({
            title: "提示",
            content: "申请退款么",
            success: function(t) {
                if (t.cancel) return !0;
                t.confirm && (wx.showLoading({
                    title: "操作中"
                }), app.util.request({
                    url: "entry/wxapp/TkOrder",
                    cachetime: "0",
                    data: {
                        order_id: e.currentTarget.dataset.id
                    },
                    success: function(t) {
                        "1" == t.data ? (wx.showToast({
                            title: "申请成功",
                            icon: "success",
                            duration: 1e3
                        }), setTimeout(function() {
                            wx.redirectTo({
                                url: "order?status=5"
                            });
                        }, 1e3)) : wx.showToast({
                            title: "请重试",
                            icon: "loading",
                            duration: 1e3
                        });
                    }
                }));
            }
        });
    },
    qrsh: function(t) {
        var ths = this,
            e = t.currentTarget.dataset.id,
            idx = t.currentTarget.dataset.indexs;
        wx.showModal({
            title: "提示",
            content: "是否确认已收到货？",
            cancelText: "否",
            confirmText: "是",
            success: function(t) {
                if (t.cancel) return !0;
                t.confirm && (wx.showLoading({
                    title: "操作中"
                }), app.util.request({
                    url: "entry/wxapp/OkOrder",
                    cachetime: "0",
                    data: {
                        order_id: e
                    },
                    success: function(t) {
                        "1" == t.data ? (wx.showToast({
                            title: "收货成功",
                            icon: "success",
                            duration: 1e3
                        }), setTimeout(function() {
                            let olist = ths.data.order_list;
                            olist[idx].order.state = 4;
                            ths.setData({
                                order_list: olist
                            })
                        }, 1e3)) : wx.showToast({
                            title: "请重试",
                            icon: "loading",
                            duration: 1e3
                        });
                    }
                }));
            }
        });
    },
    orderQrcode: function(a) {
        var o = this,
            n = o.data.order_list,
            s = a.target.dataset.index;
        wx.showLoading({
            title: "正在加载",
            mask: !0
        }), o.data.order_list[s].offline_qrcode ? (o.setData({
            hide: 0,
            qrcode: o.data.order_list[s].offline_qrcode
        }), wx.hideLoading()) : e.request({
            url: t.order.get_qrcode,
            data: {
                order_no: n[s].order_no
            },
            success: function(t) {
                0 == t.code ? o.setData({
                    hide: 0,
                    qrcode: t.data.url
                }) : wx.showModal({
                    title: "提示",
                    content: t.msg
                });
            },
            complete: function() {
                wx.hideLoading();
            }
        });
    }
}, "hide", function(t) {
    this.setData({
        hide: 1
    });
}));